#include "../../common/detail.hpp"
#include "../../client/rpc_client.hpp"

// 这些是一个 RPC（远程过程调用）框架的测试程序，主要功能是验证框架的同步调用、异步调用以及回调函数调用。
void callback(const Json::Value& result) {
    DLOG("result = %d", result.asInt());
}
int main()
{
    rcrpc::client::RpcClient client(false, "127.0.0.1", 9090);
    
    Json::Value params,result;
    params["num1"] = 12;
    params["num2"] = 21;
    bool ret = client.call("Add", params, result);
    if (ret) {
        ILOG("result = %d" , result.asInt());
    }

    rcrpc::client::RpcCaller::JsonAsyncResponse rsp_msg;
    params["num1"] = 121;
    params["num2"] = 21;
    bool ret1 = client.call("Add", params, rsp_msg);
    if (ret1) {
        result = rsp_msg.get();
        ILOG("result = %d" , result.asInt());
    }


    params["num1"] = 112;
    params["num2"] = 211;
    bool ret2 = client.call("Add", params, callback);
    DLOG("------\n");
    std::this_thread::sleep_for(std::chrono::seconds(1));
    // 程序运行结束,client自动关闭
    // 没有资源泄露，都是使用智能指针，这里不管他的关闭
    return 0;

}